package com.linux.huhx.business.service;

import com.linux.huhx.business.action.LoginAction;
import com.linux.huhx.business.dao.LoginDao;
import com.linux.huhx.utils.DateFormatUtils;
import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.Map;

/**
 * Created by huhx on 2017-05-15.
 */
public class LoginService {
    private static Logger logger = LoggerFactory.getLogger(LoginService.class);
    private LoginDao loginDao;

    public void setLoginDao(LoginDao loginDao) {
        this.loginDao = loginDao;
    }

    // 校验邮箱是否存在,true表示存在，false表示不存在
    public boolean checkEmailExist(String email) {
        return loginDao.checkEmailExist(email);
    }

    // 根据email查询出用户的主键id
    public Long queryUserIdByEmail(String email) {
        return loginDao.queryUserIdByEmail(email);
    }

    // 校验密码是否匹配
    public boolean checkPasswordMatch(Map<String, String> map) {
        return loginDao.checkPasswordMatch(map);
    }

    // 记录并当天密码错误的次数
    public void updateFailLoginCount(Map<String, Object> map) {
        loginDao.updateFailLoginCount(map);
    }

    // 更新本次登录的时间
    public void updateUserLoginTime(Map<String, Object> map) {
        loginDao.updateUserLoginTime(map);
    }

    // 得到用户的失败次数
    public int queryFailLoginCount(Map<String, Object> map) {
        // 由于注册的原因，failMap里面一定有数据
        return loginDao.queryFailLoginCount(map);
    }

    public Map<String, String> sayHello() {
        Map<String, String> map = loginDao.sayHello();
        logger.info("map content: " + map);
        return map;
    }
}
